﻿namespace PrismEx.SampleApp.Modules.SimpleNavigation
{
    using System;
    using System.ComponentModel.Composition;
    using System.Threading;

    using Microsoft.Practices.Prism.Commands;
    using Microsoft.Practices.Prism.Events;
    using Microsoft.Practices.Prism.MefExtensions.Modularity;
    using Microsoft.Practices.Prism.Modularity;

    using PrismEx.Events;
    using PrismEx.Events.Navigation;

    [ModuleExport(typeof(SimpleNavigationModule))]
    public class SimpleNavigationModule : IModule
    {
        private readonly IEventAggregator eventAggregator;

        [ImportingConstructor]
        public SimpleNavigationModule(IEventAggregator eventAggregator)
        {
            this.eventAggregator = eventAggregator;
        }

        public void Initialize()
        {
            this.eventAggregator.Publish(
                new InjectInstanceIntoRegionEvent
                    {
                        RegionName = "NavigationRegion",
                        Instance = new
                        {
                            Text = "Hello World",
                            Command = new DelegateCommand<object>(a => this.eventAggregator.Publish(new NavigateUriEvent() { RegionName = "MainRegion", Uri = new Uri(typeof(SimpleNavigationView).FullName, UriKind.Relative) }))
                        }
                    });

            Thread.Sleep(10000);
        }
    }
}
